package com.lianboke.link.ad.Views;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.lianboke.link.ad.R;
import com.lianboke.link.ad.utils.KLog;


/**
 * 自定义加载框
 */
public class CustomLoadingDialog extends Dialog {
	TextView loading_del_textview;
	String content = "";
	private Context mContext;
	private boolean isCancle;
	private ProgressBar progressBarKey;
	private TextView progressBarValue;
	
	public CustomLoadingDialog(Context context, String content,boolean isCancle) {
		super(context, R.style.custom_dialog);
		mContext = context;
	    this.content = content;
	    this.isCancle = isCancle;
	}
	
	public CustomLoadingDialog(Context context, int content) {
		super(context,R.style.custom_dialog);
		mContext = context;
		if(content > 0) {
			this.content = context.getString(content);
		}
	}

	protected void onCreate(Bundle savedInstanceState){
		 super.onCreate(savedInstanceState);
		 //设置view样式
		 setContentView(R.layout.custom_loading_dialog);
		loading_del_textview =(TextView) findViewById(R.id.loading_text_tv);
		progressBarKey = (ProgressBar) findViewById(R.id.tv_progress_key);
		progressBarValue = (TextView) findViewById(R.id.tv_progress_value);
		if(!TextUtils.isEmpty(content)){
			loading_del_textview.setText(content);
		}
		setCancelable(isCancle);
		setCanceledOnTouchOutside(isCancle);
	 }

	/**
	 * 更新等带框的内容
	 * @param content
	 */
	 public void updateLoadDialogContent(String content){
		 loading_del_textview.setText(content);
	 }
	 protected void onStop() {
		 super.onStop();
	 }
	 @Override
	public void show() {
		super.show();
		 
	}
	 @Override
	public void dismiss() {
		super.dismiss();
	}

	@Override
	protected void onStart() {
		super.onStart();
	}

	public void setProgressBarKey(int progressValue) {
		this.progressBarKey.setProgress(progressValue);
	}

	public void setProgressBarValue(int progressBarValue) {
		this.progressBarValue.setText(progressBarValue+" %");
	}

	/**
	 * 设置进度条是否显示
	 */
	public void setShowAndHideProgressBarUI(boolean isShow){
	 	if(isShow){
			setProgressBarKey(0);
			setProgressBarValue(0);
			progressBarValue.setVisibility(View.VISIBLE);
			progressBarKey.setVisibility(View.VISIBLE);
		}else{
			progressBarValue.setVisibility(View.GONE);
			progressBarKey.setVisibility(View.GONE);
		}
	}
}
